namespace nu
{
   public class Dispatcher : IDispatcher
   {
      private readonly ICommandRegistry _registry;

      public Dispatcher(ICommandRegistry registry)
      {
         _registry = registry;
         _registry.Intialize();
      }

      public void Forward(string[] args)
      {
         Parameters command = new Parameters(args);
         Find(command.CommandName).Route(command.Arguments);
      }

      public ICommand Find(string commandName)
      {
         return _registry.FindCommand(commandName) ?? DefaultCommand();
      }

      public ICommand DefaultCommand()
      {
         return _registry.FindCommand("help");
      }
   }
}